#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>

#if 0
void my_funcnew(int signum, siginfo_t *info, void *myact)
#endif

void my_func(int signum)
{
    printf("if you want to quit, please try SIGQUIT\n");
}

int main()
{
    sigset_t set, pendset;
    struct sigaction action1, action2;
    sigemptyset(&action1.sa_mask);

#if 0
    action1.sa_flags = SA_SIGINFO;
    action1.sa_sigaction = my_funcnew;
#endif

    action1.sa_flags = 0;
    action1.sa_handler = my_func;
    sigaction(SIGINT, &action1, NULL);

    if (sigemptyset(&set) < 0) {
        perror("sigemptyset");
        return -1;
    }

    if (sigaddset(&set, SIGQUIT) < 0) {
        perror("sigaddset");
        return -1;
    }

    if (sigaddset(&set, SIGINT) < 0) {
        perror("sigaddset");
        return -1;
    }

    if (sigprocmask(SIG_BLOCK, &set, NULL) < 0) {
        perror("sigprocmask");
        return -1;
    } else {
        printf("blocked\n");
    }

    if (sigismember(&set, SIGINT)) {
        perror("SIGINT in set\n");
    }

    sleep(10);

    if (sigpending(&pendset) < 0) {
        perror("get pending mask error");
    }

    if (sigismember(&pendset, SIGINT)) {
        printf("signal SIGINT is pending\n");
    }

    sleep(10);

    if (sigprocmask(SIG_UNBLOCK, &set, NULL) < 0) {
        perror("sigprocmask");
        return -1;
    } else {
        printf("unblock\n");
    }

    while (1) {
        sleep(1);
    }

    return 0;
}